<template>
  <view class="coupon-card" :class="status" @click="$emit('click')">
    <view class="coupon-left">
      <view class="coupon-value">
        <text v-if="coupon.type === 'discount'">{{coupon.value}}折</text>
        <template v-else>
          <text class="symbol">¥</text>
          <text class="amount">{{coupon.value}}</text>
        </template>
      </view>
      <text class="coupon-condition" v-if="coupon.minAmount">满{{coupon.minAmount}}元可用</text>
      <text class="coupon-condition" v-else>无门槛券</text>
    </view>
    <view class="coupon-divider"></view>
    <view class="coupon-right">
      <view class="coupon-name">{{coupon.name}}</view>
      <view class="coupon-validity">有效期至{{coupon.validDate}}</view>
      <view class="coupon-desc" v-if="coupon.desc">{{coupon.desc}}</view>
      <view class="coupon-status">{{statusText}}</view>
    </view>
    <view class="coupon-corner" v-if="status !== 'usable'">
      <image :src="cornerImage" class="corner-img"></image>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    coupon: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    status() {
      return this.coupon.status || 'usable'
    },
    statusText() {
      const statusMap = {
        usable: '立即使用',
        used: '已使用',
        expired: '已过期'
      }
      return statusMap[this.status]
    },
    cornerImage() {
      const images = {
        used: '/static/coupon-used.png',
        expired: '/static/coupon-expired.png'
      }
      return images[this.status] || ''
    }
  }
}
</script>

<style lang="scss">
$primary-color: #FF7F00;

.coupon-card {
  display: flex;
  height: 100px;
  margin-bottom: 15px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  
  &.usable {
    background: linear-gradient(135deg, #FF9E40, #FF7F00);
    color: #fff;
    
    .coupon-divider {
      background: repeating-linear-gradient(
        transparent 0px,
        transparent 4px,
        rgba(255,255,255,0.3) 4px,
        rgba(255,255,255,0.3) 8px
      );
    }
    
    .coupon-value {
      color: #fff;
    }
    
    .coupon-condition {
      color: rgba(255,255,255,0.8);
    }
    
    .coupon-name {
      color: #fff;
    }
    
    .coupon-validity,
    .coupon-desc {
      color: rgba(255,255,255,0.8);
    }
    
    .coupon-status {
      background: rgba(255,255,255,0.2);
      color: #fff;
    }
  }
  
  &.used, &.expired {
    background: #f5f5f5;
    color: #999;
    
    .coupon-divider {
      background: repeating-linear-gradient(
        transparent 0px,
        transparent 4px,
        #ddd 4px,
        #ddd 8px
      );
    }
  }
  
  .coupon-left {
    width: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
  }
  
  .coupon-value {
    font-size: 32px;
    font-weight: bold;
    line-height: 1;
    margin-bottom: 5px;
    
    .symbol {
      font-size: 20px;
      margin-right: 2px;
    }
    
    .amount {
      font-size: 32px;
    }
  }
  
  .coupon-condition {
    font-size: 12px;
  }
  
  .coupon-divider {
    width: 1px;
    height: 100%;
    background: #ddd;
  }
  
  .coupon-right {
    flex: 1;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  
  .coupon-name {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 5px;
  }
  
  .coupon-validity {
    font-size: 12px;
    margin-bottom: 5px;
  }
  
  .coupon-desc {
    font-size: 12px;
  }
  
  .coupon-status {
    position: absolute;
    bottom: 10px;
    right: 10px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 10px;
  }
  
  .coupon-corner {
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    height: 50px;
    overflow: hidden;
    
    .corner-img {
      width: 50px;
      height: 50px;
    }
  }
}
</style>